import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:h_flutter_119/mixin/toast_mixin.dart';
import 'package:h_flutter_119/res/colors.dart';

class SearchPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => _SearchPageState();

}

class _SearchPageState extends State<SearchPage> with ToastMixin{

  late TextEditingController _editingController;

  String inputValue = "";

  @override
  void initState() {
    super.initState();
    _editingController = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: () {
            var canPop = Navigator.canPop(context);
            if (canPop != null && canPop) {
              Navigator.pop(context);
            } else {
              SystemNavigator.pop(animated: true);
            }
          },
          icon: Icon(Icons.arrow_back_ios),
        ),
        title: _creatInputWidget(context),
        actions: [
          IconButton(
              onPressed: () {
                showToast(inputValue.isEmpty?"请输入搜索内容":inputValue);}, icon: const Icon(Icons.search))
        ],
      ),
    );
  }

  Widget _creatInputWidget(BuildContext context) {
    var outlineBorder = OutlineInputBorder(
        borderRadius:BorderRadius.all(Radius.circular(10.w)),
        borderSide:BorderSide(color: Colors.white,width: 1.w)
    );
    return Container(
      height: 80.w,
      alignment: Alignment.center,
      child: TextField(
        textAlignVertical: TextAlignVertical.bottom,
        textAlign: TextAlign.left,
        style: TextStyle(fontSize: 32.sp,color: Colors.white),
        cursorColor: Colors.white,
        maxLines: 1,
        controller: _editingController,
        decoration: InputDecoration(
          hintText: '请输入搜索内容',
          border: InputBorder.none,
          enabledBorder: outlineBorder,
          focusedBorder: outlineBorder,
          hintStyle:TextStyle(color: ColorStyle.color_CCCCCC,fontSize: 32.sp),
        ),
        onChanged: (value){
          setState((){
            inputValue = value;
          });
        },
      ),
    );
  }

}
